const sass = require('sass');
const loadGruntTasks = require('load-grunt-tasks');

module.exports = grunt => {
  // 多目标模式，可以让任务根据配置形成多个子任务
  grunt.initConfig({
    clean: {
      temp: 'temp/app.js'
    },
    sass: {
      options: {
        sourceMap: true,
        implementation: sass
      },
      main: {
        files: {
          'dist/css/main.css': 'sass/main.scss',
        }
      }
    },
    babel: {
      options: {
        presets: ['@babel/preset-env'],
      },
      main: {
        files: {
          'dist/js/app.js': 'src/js/app.js'
        }
      }
    },
    watch: {
      js: {
        files: ['src/js/*.js'],
        tasks: ['babel']
      },
      css: {
        files: ['sass/*.scss'],
        tasks: ['sass'],
      }
    },
  })

  loadGruntTasks(grunt); // 会自动加载所有的grunt拆件中的任务

  grunt.registerTask('default', ['sass', 'babel', 'watch']);
}